package com.bbs.dao;

import java.sql.Connection;
import java.sql.Date;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.List;

import org.apache.log4j.Logger;

import com.bbs.bean.ReplyBBSOfAutoHome;
import com.car.util.Util;

public class HuiFuDAOOfAutoHome {
	static Logger logger = Logger.getLogger(HuiFuDAOOfAutoHome.class.getName());
	private Connection conn;

	public List<Integer> getUserID() {
		List<Integer> uid = new ArrayList<>();
		Statement st = null;
		ResultSet rs = null;
		//String sql = "SELECT DISTINCT uid FROM (SELECT kb_yhid as uid FROM qczj_kb UNION ALL SELECT price_uid AS uid FROM qczj_price) AS b";
		String sql = "SELECT DISTINCT ck_uid as uid FROM autohome.qczj_yh_ck WHERE ck_rz=1 AND ck_uid NOT IN(SELECT DISTINCT hf_yhid FROM autohome.qczj_yh_hf)";
		try {
			st = conn.createStatement();
			rs = st.executeQuery(sql);
			while (rs.next()) {
				uid.add(rs.getInt("uid"));
			}
		} catch (SQLException e) {
			e.printStackTrace();
		}
		return uid;
	}

	public boolean insertHuiFu(ReplyBBSOfAutoHome rb) {
		boolean isInsert = false;
		PreparedStatement ps = null;
		String sql = "INSERT INTO qczj_yh_hf(hf_yhid,hf_clubid,hf_bbsid,hf_bt,hf_nr,hf_hfuid,hf_lc,hf_time) VALUES(?,?,?,?,?,?,?,?)";
		try {
			ps = conn.prepareStatement(sql);
			ps.setInt(1, rb.getHf_yhid());
			ps.setInt(2, rb.getHf_clubid());
			ps.setInt(3, rb.getHf_bbsid());
			ps.setString(4, rb.getHf_bt());
			ps.setString(5, rb.getHf_nr());
			ps.setInt(6, rb.getHf_hfuid());
			ps.setInt(7, rb.getHf_lc());
			ps.setDate(8, (Date) Util.getDate(rb.getHf_time()));
			isInsert = ps.executeUpdate() > 0 ? true : false;
			logger.info("用户ID=" + rb.getHf_yhid() + "的回复插入成功！");
		} catch (SQLException e) {
			logger.error("用户ID=" + rb.getHf_yhid() + "的回复插入失败！");
		}
		return isInsert;
	}

	public HuiFuDAOOfAutoHome(Connection conn) {
		super();
		this.conn = conn;
	}

}